package com.wanyang.controller;

import com.wanyang.service.CommonService;
import com.wanyang.service.OpenApiAuthService;
import com.wanyang.vo.ApiResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("open")
public class OpenApiController {

    @Autowired
    private CommonService commonService;

    @Autowired
    private OpenApiAuthService openApiAuthService;

    @ApiOperation(value = "上传图片")
    @PostMapping("upload/img")
    public ApiResult uploadImg(MultipartFile multipartFile, @RequestHeader String appId, @RequestHeader String secret) {
        openApiAuthService.validate(appId, secret);
        return ApiResult.success(commonService.uploadImg(multipartFile), null);
    }

    @ApiOperation(value = "上传视频")
    @PostMapping("upload/video")
    public ApiResult uploadVideo(MultipartFile multipartFile, @RequestHeader String appId, @RequestHeader String secret) {
        openApiAuthService.validate(appId, secret);
        return ApiResult.success(commonService.uploadVideo(multipartFile), null);
    }

}
